package admin

import "object/go_cms/models"

type UploadFileAdminController struct {
	BaseAdminController
	models models.UploadFileModels
}

// @router /admin/upload_file/indexUI [get]
func (u *UploadFileAdminController) IndexUI() {
	u.TplAdmin("upload_file/index")
}

// @router /admin/upload_file/get [get,post]
func (u *UploadFileAdminController) Get() {
	id, _ := u.GetUint64("id")
	u.Res.Data, _ = u.models.Get(id)
	u.Res.Code = 1
	u.Json(u.Res)
}

// @router /admin/upload_file/query [get,post]
func (u *UploadFileAdminController) QueryByPage() {
	maps := u.GetParamMap()
	u.Res.Data, u.Res.Count = u.models.QueryByPage(maps)
	u.Res.Code = 0
	u.Json(u.Res)
}

// @router /admin/upload_file/delete [get,post]
func (u *UploadFileAdminController) Delete() {
	id, _ := u.GetUint64("id")
	_, err := u.models.Delete(id)
	if err != nil {
		u.Res.Code = 0
		u.Res.Msg = err.Error()
	} else {
		u.Res.Code = 1
		u.Res.Msg = "删除成功"
	}
	u.Json(u.Res)
}

// 文件下载
// @router /admin/upload_file/download [get,post]
func (u *UploadFileAdminController) DownloadFile() {
	id, _ := u.GetUint64("id")
	upload, _ := u.models.Get(id)

	u.Ctx.Output.Download(upload.Path+"/"+upload.File_name, upload.Upload_name)
}
